package cn.wolfcode.p2p.business.service.impl;
import java.util.Date;

import cn.wolfcode.p2p.business.domain.BidRequest;
import cn.wolfcode.p2p.business.domain.SystemAccount;
import cn.wolfcode.p2p.business.domain.SystemAccountFlow;
import cn.wolfcode.p2p.business.mapper.SystemAccountFlowMapper;
import cn.wolfcode.p2p.business.service.ISystemAccountFlowService;
import cn.wolfcode.p2p.util.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

@Service
@Transactional
public class SystemAccountFlowServiceImpl implements ISystemAccountFlowService {
        @Autowired
        private SystemAccountFlowMapper systemAccountFlowMapper;

        @Override
        public void createBidRequestManagementCharge(SystemAccount systemAccount, BigDecimal amount, BidRequest br) {
                SystemAccountFlow sf = new SystemAccountFlow();
                sf.setActionDate(new Date());
                sf.setActionType(Constants.SYSTEM_ACCOUNT_ACTIONTYPE_MANAGE_CHARGE);
                sf.setAmount(amount);
                sf.setNote("收取借款"+br.getTitle()+"借款管理费,金额为:"+amount);
                sf.setUsableAmount(systemAccount.getUsableAmount());
                sf.setFreezedAmount(systemAccount.getFreezedAmount());
                systemAccountFlowMapper.insert(sf);
        }

        @Override
        public void createInterestManagerChargeFlow(SystemAccount systemAccount, BigDecimal interestManagerCharge) {
                SystemAccountFlow sf = new SystemAccountFlow();
                sf.setActionDate(new Date());
                sf.setActionType(Constants.SYSTEM_ACCOUNT_ACTIONTYPE_INTREST_MANAGE_CHARGE);
                sf.setAmount(interestManagerCharge);
                sf.setNote("收取利息管理费金额为:"+interestManagerCharge);
                sf.setUsableAmount(systemAccount.getUsableAmount());
                sf.setFreezedAmount(systemAccount.getFreezedAmount());
                systemAccountFlowMapper.insert(sf);
        }
}
